/*
 * wgnd.c
 *
 * Created: 13.02.2013 16:41:40
 *  Author: saenko
 */ 


#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdio.h>

volatile uint8_t wiegand_count;
volatile uint8_t wiegand_frame;
volatile uint8_t wiegand_buf[64];


void wiegand_init(void)
{
	PORTD = 0b00001100;
	
	EICRA = (1<<ISC11)|(1<<ISC01);
	EIMSK = (1<<INT1)|(1<<INT0);
	
	TCCR1B = (1<<CS12);
}

ISR(INT0_vect)
{
/*	wiegand_buf[wiegand_count] = '0';
	wiegand_count++;
	TCNT1 = 49911;
	TIMSK1 = (1<<TOIE1);*/
	putchr(0);
/*	unsigned char temp = TCNT1L;
	putchr(TCNT1H);
	putchr(TCNT1L);*/
}

ISR(INT1_vect)
{
/*	wiegand_buf[wiegand_count] = '1';
	wiegand_count++;
	TCNT1 = 49911;
	TIMSK1 = (1<<TOIE1);*/
	putchr(1);
/*	unsigned char temp = TCNT1L;
	putchr(TCNT1H);
	putchr(TCNT1L);*/
}

ISR(TIMER1_OVF_vect)
{
	TIMSK1 = 0;
	putchr(13);
//	wiegand_frame = 1;

}

